package com.yy.istio.service;

import com.yy.istio.util.SystemEnvUtil;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class HelloService {

    @Resource
    private RestTemplate restTemplate;

    private static final String TEST_URI = "/istio-demo2/hello/test";

    private static final String ISTIO_DEMO2_URL= "localhost:8081";

    private static final String ISTIO_DEMO2_SERVICE = "ISTIO_DEMO2_SERVICE";

    public String test(){
        String result = Strings.EMPTY;
        String url = String.format("http://%s"+ TEST_URI, SystemEnvUtil.getProperty(ISTIO_DEMO2_SERVICE,ISTIO_DEMO2_URL));
        try{
            System.out.println("url ----->>>>> "+url);
            result = restTemplate.getForObject(url, String.class);
            System.out.println(result);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


}
